﻿<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title>代码生成器</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
        content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../layuiAdmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../layuiAdmin/style/admin.css" media="all">
</head>

<body>
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <input type="text" name="name" placeholder="请输入表名称" autocomplete="new-password"
                            class="layui-input">
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="table-search">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
            <div class="layui-card-body">
                <table id="code_generate" lay-filter="code_generate"></table>
            </div>
        </div>
    </div>
    <script src="../../layuiAdmin/layui/layui.js"></script>
    <script>
        layui.config({
            base: '../../layuiAdmin/', //静态资源所在路径
            version: top.layui.setter.version
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'table', 'util'], function () {
            var $ = layui.$,
                form = layui.form,
                table = layui.table,
                util = layui.util,
                admin = layui.admin;
            var areaName = "code_generate";
            //监听搜索
            form.on('submit(table-search)', function (data) {
                var field = data.field;

                //执行重载
                table.reload(areaName, {
                    where: { queryJson: JSON.stringify(field) },
                    page: {
                        curr: 1
                    }
                });
            });
            //数据库表
            table.render({
                elem: '#' + areaName,
                toolbar: $.getToolButtons(),
                defaultToolbar: [],
                url: '/api/Code/GetTablePageList',
                cols: [
                    [
                        { field: 'number', title: '序号', width: 100, align: 'center', type: 'numbers' },
                        { field: 'name', title: '表名', minWidth: 80, align: 'center' },
                        { field: 'pk', title: '主键', minWidth: 80 },
                        { field: 'sumrows', title: '记录数', minWidth: 80, align: 'center' },
                        { field: 'reserved', title: '使用大小', align: 'center' },
                        { field: 'tdescription', title: '说明', align: 'center' },
                    ]
                ],
                page: true,
                limit: 100,
                height: 'full-110',
                text: '对不起，加载出现异常！'
            });
            var selectRow = null;
            table.on('row(' + areaName + ')', function (obj) {
                selectRow = obj.data;
                obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
            });

            var generate = function () {
                if (selectRow == null) return layer.msg('请选择数据');
                $.OpenTab({
                    type: 2,
                    title: '代码生成器',
                    skin: 'layer-ext-xinskin',
                    content: 'codegenerateform.html?tableName=' + selectRow.name,
                    area: ['1050px', '645px']
                });
            }
            //事件
            util.event('lay-active', {
                'x-generate': () => generate()
            });
        });
    </script>
</body>

</html>